#include "Attribute.h"
#include "IVisitor.h"

Attribute::Attribute(const exprTypePtr& value, const NameTokPtr& attr, int ctx, int nodeId):
    exprType(nodeId),
    _value(value),
    _attr(attr),
    _ctx(ctx)
{
}
    
Attribute::~Attribute()
{
    
}
    
Ast::AstTypes Attribute::type() const
{
    return Ast::Attribute;
}
    

exprTypePtr Attribute::value()
{
    return _value;
}

void Attribute::setValue(const exprTypePtr& value)
{
    _value = value;
}

NameTokPtr Attribute::attr()
{
    return _attr;
}

void Attribute::setAttr(const NameTokPtr& attr)
{
    _attr = attr;
}

int Attribute::ctx()
{
    return _ctx;
}

void Attribute::setCtx(int ctx)
{
    _ctx = ctx;
}

    
QString Attribute::toString() const
{
    return QString("Attribute[value=%1, attr=%2, ctx=%3]").
                arg(_value ? _value->toString():"").
                arg(_attr ? _attr->toString():"").
                arg(_ctx);
}
    
void Attribute::accept(IVisitor* visitor, const SimpleNodePtr& node)
{
    visitor->visitAttribute(node.dynamicCast<Attribute>());
}
    
void Attribute::traverse(IVisitor* visitor)
{
    if (_value != NULL)
        _value->accept(visitor, _value);
    if (_attr != NULL)
        _attr->accept(visitor, _attr);
}